﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Demo</title>
    @*     <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
    <title>Layui 导入按钮示例</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/layui/2.6.8/css/layui.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/layui/2.6.8/layui.js"></script>
    <link href="//unpkg.com/layui@2.9.20/dist/css/layui.css" rel="stylesheet">  *@
    @* <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/layui@2.9.20/dist/css/layui.min.css"> *@
</head>

<script src="//unpkg.com/layui@2.9.21-rc/dist/layui.js"></script>
<body class="layui-padding-3">
    <h3>库存调度</h3>
    <form class="layui-form layui-row layui-col-space16">
        <div class="layui-form-item">
            <div class="layui-col-md4">
                <div class="layui-input-wrap">
                    <div class="layui-input-prefix"></div>
                    <label class="layui-form-label">调拨单编码：</label>
                    <input type="text"
                           name="A"
                           id="AllocateNumber"
                           placeholder="" lk
                           class="layui-input"
                           lay-affix="clear"
                           style="width: 200px" />
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-input-wrap">
                    <div class="layui-input-prefix"></div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">来源仓库</label>
                        <div class="layui-input-block" style="width: 200px">
                            <select name="interest" id="SourcerepositoryId">
                                <option value=-1>选择仓库</option>

                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-input-wrap">
                    <div class="layui-input-prefix"></div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">目标仓库</label>
                        <div class="layui-input-block" style="width: 200px">
                            <select name="interest" lay-filter="aihao" id="TargetrepositoryId">
                                <option value=-1>选择仓库</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">调拨时间</label>
                <div class="layui-input-inline layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-date"></i>
                    </div>
                    <input type="text" name="date" id="AllocateDate" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-input-wrap">
                    <div class="layui-input-prefix"></div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block" style="width: 200px">
                            <select name="interest" lay-filter="aihao" id="Status">
                                <option value=-1>选择状态</option>
                                <option value=1>新增</option>
                                <option value=2>变更</option>
                                <option value=3>确定</option>
                                <option value=4>取消</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        <div class="layui-col-md4">
            <a class="layui-btn" lay-submit onclick="location.href='/Inventory/InventoryAdd'">
                新增调拨单
            </a>
            <button class="layui-btn layui-bg-blue" lay-submit lay-filter="search">
                查询
            </button>
        </div>

    </form>
    <table class="layui-hide" id="ID-table-demo-search"></table>

    <script>
        layui.use(function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var util = layui.util;
            var table = layui.table;
            var upload = layui.upload;
            var $ = layui.$;

            // 日期
            laydate.render({
                elem: '#AllocateDate'
            });
            var formData = {
                AllocateNumber: "",
                SourcerepositoryId: -1,
                TargetrepositoryId: -1,
                AllocateDate: "",
                Status: -1
            };
            Seach();


            //绑定来源仓库
            $.ajax({
                url: '@ViewBag.RBACWrite' + "/api/Warehouse/WareHouseList?Name=" + "" + '&Status=' + -1,
                type: 'get',
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    $.each(res.data, function () {
                        $("#SourcerepositoryId").append(`<option value="${this.warehouseId}">${this.warehouseName}</option>`)
                    })
                    form.render('select'); // 重新渲染下拉框
                }
            })

            //绑定目标仓库
            $.ajax({
                url: '@ViewBag.RBACWrite' + "/api/Warehouse/WareHouseList?Name=" + "" + '&Status=' + -1,
                type: 'get',
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    $.each(res.data, function () {
                        $("#TargetrepositoryId").append(`<option value="${this.warehouseId}">${this.warehouseName}</option>`)
                    })
                    form.render('select'); // 重新渲染下拉框
                }
            })


            // 查询事件
            form.on('submit(search)', function (data) {
                var field = data.field; // 获取表单字段值
                // 显示填写结果，仅作演示用
                formData.AllocateNumber = $("#AllocateNumber").val();
                formData.SourcerepositoryId = $("#SourcerepositoryId").val();
                formData.TargetrepositoryId = $("#TargetrepositoryId").val();
                formData.AllocateDate = $("#AllocateDate").val();
                formData.Status = $("#Status").val();
                Seach();
                return false; // 阻止默认 form 跳转
            });

            // 搜索提交
            function Seach() {
                console.log(formData);
                var InventoryUrl = '@ViewBag.RBACWrite' + "/api/Inventory/InventorySearch?AllocateNumber=" + formData.AllocateNumber + '&SourcerepositoryId=' + formData.SourcerepositoryId + '&TargetrepositoryId=' + formData.TargetrepositoryId + '&AllocateDate=' + formData.AllocateDate + '&Status=' + formData.Status;
                $.ajax({
                    url: InventoryUrl,
                    type: 'get',
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        table.render({
                            elem: '#ID-table-demo-search',
                            cols: [
                                [
                                    { field: 'inventoryId', title: '序号', width: 80 },
                                    { field: 'allocateNumber', title: '单据编码', width: 120 },
                                    { field: 'sourcerepositoryName', title: '来源仓库', width: 120 },
                                    { field: 'targetrepositoryName', title: '目标仓库', width: 100 },
                                    { field: 'allocateDate', title: '调拨时间', width: 100 },
                                    { field: 'createName', title: '制单人', width: 100 },
                                    { field: 'markdepartmentName', title: '制单部门', width: 100 },
                                    { field: 'createTime', title: '创建时间', width: 100 },
                                    { field: 'statusName', title: '状态', width: 100 },
                                    { field: 'produceplanAuditName', title: '审批状态', width: 100 },
                                    {
                                        fixed: 'right',
                                        title: '操作',
                                        width: 134,
                                        minWidth: 125,
                                        templet: '#toolDemo',
                                    },
                                ],
                            ],
                            toolbar: '#demo-toolbar-setRowChecked',
                            data: res.data,
                            page: true,
                            limits: [2, 3, 4],
                            height: 310
                        });
                        return;

                    }
                });
            };
            // //删除事件
            // form.on('submit(Del)', function () {
            //     // 行单击事件( 双击事件为: rowDouble )
            //     table.on('row(ID-table-demo-search)', function (obj) {
            //         var id = obj.data.produceplanId; // 获取当前行数据
            //         console.log(id);
            //         var data = {
            //             produceplanId: id
            //         };
            //         $.post({
            //             url: '@ViewBag.RBACWrite' + "/api/produceplan/produceplanDelete",
            //             data: JSON.stringify(data),
            //             dataType: "json",
            //             contentType: "application/json",
            //             success: res => {
            //                 if (res.code == 1) {
            //                     layer.msg("删除成功", { icon: 1, time: 1000 }, function () {
            //                         setTimeout(function () {
            //                             location.reload();//刷新页面
            //                         }, 500)
            //                     });
            //                 }
            //                 else {
            //                     layer.alert("删除失败");
            //                     return;
            //                 }
            //             }
            //         })
            //     });

            // });

            
            //修改方法
            // form.on('submit(Upd)', function () {
            //     // 行单击事件( 双击事件为: rowDouble )
            //     table.on('row(ID-table-demo-search)', function (obj) {
            //         var id = obj.data.produceplanId; // 获取当前行数据
            //         console.log(id);
            //         localStorage.setItem("ProduceplanId", id);
            //         location.href = '/produceplan/produceplanUpdate';
            //     });
            // });
        });



    </script>
    <script type="text/html" id="toolDemo">
        <div class="layui-clear-space" >
            <a lay-submit style = "color:cornflowerblue;cursor:pointer"   lay-filter="Upd" > 编辑 </a>&emsp;&emsp;
                <a lay-submit style = "color:red;cursor:pointer" lay-filter="Del" > 删除 </a>
        </div>
    </script>
</body>
</html>
